package cn.fayang.ymcc.mq.consumer;

import cn.fayang.ymcc.domain.MessageStation;
import cn.fayang.ymcc.service.ICourseService;
import com.alibaba.fastjson.JSONObject;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

@Component
@RocketMQMessageListener(
        consumerGroup="common-consumer-group",
        topic="common-topic",
        selectorExpression="common-tags"
)
public class StationMessageConsumer implements RocketMQListener<MessageExt> {
    @Autowired
    private ICourseService courseService;
    @Override
    public void onMessage(MessageExt messageExt) {
        String jsonStr = new String(messageExt.getBody(), StandardCharsets.UTF_8);
        MessageStation messageStation = JSONObject.parseObject(jsonStr, MessageStation.class);
        courseService.saveMessageStation(messageStation);
    }
}
